package cn.three.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.three.biz.ShopdaoBiz;
import cn.three.eneity.Admin;
import cn.three.eneity.Classify;
import cn.three.eneity.Shop;

public class editShopServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		Shop shop=new Shop();
		int shopid =Integer.parseInt(request.getParameter("shopid"));
		shop.setShopId(shopid);
		
		String shopname=request.getParameter("shopname");
        shop.setShopName(shopname);
    
		
		String shoppr= request.getParameter("shopprice");
        int shopprice = Integer.parseInt(shoppr);
        shop.setShopPrice(shopprice);
        
        String shopdetails= request.getParameter("shopdetalis");
        shop.setShopDetails(shopdetails);
        
        String shopcou= request.getParameter("shopcount");
        int shopcount = Integer.parseInt(shopcou);
        shop.setShopCount(shopcount);
        
        String pic =request.getParameter("pic");
        shop.setShopPic(pic);
        
        HttpSession session=request.getSession();
        Admin admin = (Admin) session.getAttribute("admin");
        int adminid=admin.getAdminId();
        admin.setAdminId(adminid);
        shop.setAdmin(admin);
      
        
        String classifyname =request.getParameter("classify");
        int classifyid = Integer.parseInt(classifyname);
        Classify  classify=new Classify();
	    classify.setClassifyId(classifyid);
	    shop.setClassify(classify);  
	     
	     
		       ShopdaoBiz shopBiz = new ShopdaoBiz();
		   int s =shopBiz.updateShop(shop);
		          if (s>0){
		         response.sendRedirect("shop.jsp");
		          }else{
		          	response.sendRedirect("edit_Shop.jsp");
		          	}
	        
	}
		
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
